Skip to content

Fix bug #69168: DomNode::getNodePath() returns invalid path #10318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

nielsdos
Copy link
Member

@nielsdos nielsdos commented Jan 14, 2023

Fixes bug #69168 (old bug tracker)
The root cause of this bug is that we're copying the node, which breaks the connection to the parent. So getting the parent or getting the path doesn't work.

The reason for the copy is the following:
Upon freeing libxslt's context, every document which is not the main document will be freed by libxslt.
If a node of a document which is not the main document gets returned to userland, we'd free the node twice:

  • first by the cleanup of the xslt context
  • and then by our own refcounting mechanism.

This was reported in bug #49634 (old bug tracker), and was fixed by always copying the node (and later re-fixed in bug #70078 (old bug tracker)).
The original fix is not entirely correct unfortunately because of the following two main reasons:

  • modifications to the node will only modify the copy, and not the original
  • accesses to the parent, path, ... will not work

This patch fixes it properly by only copying the node if it origins from a document other than the main document.
And by doing so, consequently fixes bug #69168 (old bug tracker).

Targeting master because this technically is a BC break because the original node gets returned instead of a copy, so modifications will now persist.
As an additional plus to this PR, the transformation will now use less memory.
Requesting a review from @cmb69 because he previously fixed a bug in this function and also verified the bug report.

EDIT: failure in Travis is from proc_open [ext/standard/tests/general_functions/proc_open02.phpt] again, which is unrelated.

@nielsdos nielsdos changed the title Fix bug #69168 @nielsdos Fix bug #69168: DomNode::getNodePath() returns invalid path Jan 14, 2023
@nielsdos nielsdos changed the title @nielsdos Fix bug #69168: DomNode::getNodePath() returns invalid path Fix bug #69168: DomNode::getNodePath() returns invalid path Jan 14, 2023
@devnexen devnexen requested a review from cmb69 January 14, 2023 18:47
Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

That's a great analysis, and the fix looks good!

Targeting master because this technically is a BC break because the original node gets returned instead of a copy, so modifications will now persist.

Makes sense to me to target master, especially because the issue is quite old.

Upon freeing libxslt's context, every document which is not the *main*
document will be freed by libxslt. If a node of a document which is not
the main document gets returned to userland, we'd free the node twice:
 - first by the cleanup of the xslt context
 - and then by our own refcounting mechanism.
This was reported in bug #49634, and was fixed by always copying the
node (and later re-fixed in bug #70078).
The original fix is not entirely correct unfortunately because of the
following two main reasons:
 - modifications to the node will only modify the copy, and not the original
 - accesses to the parent, path, ... will not work

This patch fixes it properly by only copying the node if it origins from
a document other than the main document.
This additionally tests for modifications of nodes.

Co-authored-by: juha.ikavalko@agentit.fi
@nielsdos
Copy link
Member Author

Fixed the codestyle :) Thanks.

@cmb69 cmb69 closed this in 1925855 Jan 19, 2023
@cmb69
Copy link
Member

cmb69 commented Jan 19, 2023

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants